package com.kefu.exam.controller;

import com.kefu.exam.vo.ExamCascadeJumpSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;
import com.kefu.exam.model.ExamCascadeJump;
import com.kefu.exam.service.ExamCascadeJumpService;
import com.kefu.exam.vo.ExamCascadeJumpSearchVo;
import com.kefu.exam.vo.ExamCascadeJumpUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * @author xiaoyu
 * @date 2022/10/24
 */
@RestController
@Api(tags = "级联跳转规则表")
@RequestMapping("exam/cascade")
public class ExamCascadeJumpController extends AbstractBaseController {

    @Autowired
    private ExamCascadeJumpService examCascadeJumpService;

    @PostMapping("/adds")
    @ApiOperation(value = "新增级联跳转规则")
    public Result<String> add(@Validated @RequestBody ExamCascadeJumpSaveVo examCascadeJumpSaveVo) {
    	logger.info("新增级联跳转规则表:{}", examCascadeJumpSaveVo);

        examCascadeJumpService.saveBatchCascadeJump(examCascadeJumpSaveVo);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除级联跳转规则")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除级联跳转规则表:{}", delete);
    	
        examCascadeJumpService.removeById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改级联跳转规则")
    public Result<String> update(@Validated @RequestBody ExamCascadeJumpUpdateVo examCascadeJumpVo) {
    	logger.info("修改级联跳转规则表:{}", examCascadeJumpVo);
    	
    	ExamCascadeJump info = examCascadeJumpVo.convert();
        examCascadeJumpService.updateById(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    @ApiOperation(value = "级联跳转规则表详情")
    public Result<ExamCascadeJump> detail(@Validated @RequestBody DetailVo detail) {

        ExamCascadeJump examCascadeJump = examCascadeJumpService.getById(detail.getId());
        return ResultGenerator.genSuccessResult(examCascadeJump);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询级联跳转规则表")
    public Result<Page<ExamCascadeJump>> list(@Validated @RequestBody ExamCascadeJumpSearchVo search) {    

        Page<ExamCascadeJump> page = examCascadeJumpService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }
}
